package com.gorkr.labuladong.data_struct.array;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author gorkr
 * @date 2022/06/03 18:25
 **/
public class M1109CoporateFlightBookings {

    public int[] corpFlightBookings(int[][] bookings, int n) {

        // 差分数组 初始化全为0
        int[] diff = new int[n+1];

        for (int i = 0; i < bookings.length; i++) {
          diff[bookings[i][0]-1] +=bookings[i][2];
          diff[bookings[i][1]] -=bookings[i][2];
        }

        int[] res = new int[n];
        res[0] = diff[0];
        for (int i = 1; i < n; i++) {
            res[i] = res[i-1]+diff[i];
        }
        return res;
    }

    @Test
    public void test(){
        int[][] nums = {{1,2,10},{2,3,20},{2,5,25}};
        System.out.println(Arrays.toString(corpFlightBookings(nums, 5)));


    }

}
    